﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RKMSikraKulingram
{
    public partial class SearchForm : Form
    {
        # region Private Data Members

        private PersonTransactionsForm _personTransactionsForm;

        # endregion

        public SearchForm()
        {
            InitializeComponent();
        }

        private void SearchForm_Load(object sender, EventArgs e)
        {
            this.Owner.Enabled = false;

            dateTimePickerEntryDateTo.Value = DateTime.Now;
        }

        void SearchForm_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
        {
            this.Owner.Enabled = true;
        }

        private void buttonSearch_Click(object sender, EventArgs e)
        {
            DateTime? entryDateFrom;
            if(dateTimePickerEntryDateFrom.Value == DateTime.MinValue)
                entryDateFrom = null;
            else
                entryDateFrom = dateTimePickerEntryDateFrom.Value;
            
            DateTime? entryDateTo;
            if (dateTimePickerEntryDateTo.Value == DateTime.MinValue)
                entryDateTo = null;
            else
                entryDateTo = dateTimePickerEntryDateTo.Value;

            this.searchPersonDetailsTableAdapter.Fill
           (this.sikraDataSet.SearchPersonDetails,
            textBoxFirstName.Text, textBoxLastName.Text, textBoxAddressLine1.Text,
            null, null, textBoxPhoneNumber.Text, textBoxEmail.Text, entryDateFrom, entryDateTo);
            
            this.dataGridViewDetails.Refresh();
        }

        private void dataGridViewDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        void dataGridViewDetails_CellDoubleClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
        {
            int personID = int.Parse(this.dataGridViewDetails.Rows[e.RowIndex].Cells["PersonID"].Value.ToString());
            _personTransactionsForm = new PersonTransactionsForm(personID, this.dateTimePickerEntryDateFrom.Value, this.dateTimePickerEntryDateTo.Value);
            _personTransactionsForm.Show(this);
        }
    }
}
